<template>
    <div>
        <h1>科室添加</h1>
        科室名称<input type="text" v-model="info.names">
        时间<input type="date" v-model="info.con">-<input type="date" v-model="info.end">
        <input type="button" value="查询" @click="getlist">
        <input type="button" value="清空" @click="ror">
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>Id</td>
                    <td>科室名称</td>
                    <td>科室人数</td>
                    <td>科室描述</td>
                    <td>创建日期</td>
                    <td>操作</td>
                </tr>

                <tr v-for="itme in data.list">
                    <td>{{ itme.Id }}</td>
                    <td>{{ itme.Name }}</td>
                    <td>{{ itme.ProPel }}</td>
                    <td>{{ itme.MiaoShu }}</td>
                    <td>{{ itme.ConTime }}</td>
                    <td><input type="button" value="删除" @click="del(itme.Id)">
                        <input type="button" value="修改" @click="xg(itme.Id)">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import axios from 'axios';
import { useRouter, useRoute } from 'vue-router';
const router = useRouter();
const route = useRoute();
let info: any = reactive({
    names: '',
    con: '',
    end: ''
})
let data: any = reactive({
    list: []
})
onMounted(() => {
    getlist();
})

const ror = () => {
    info.names = '',
        info.con = '',
        info.end = ''
}

//==================================显示

const getlist = () => {
    axios({
        url: '/api/KS/KSShow',
        method: 'get',
        params: info
    })
        .then((res) => {
            console.log(res);
            data.list = res.data

        })
        .catch((err) => {
            console.log(err);

        })
}
//==================================删除
const del = (id: any) => {
    let f = confirm("确认删除吗?")
    if (f) {
        axios({
            url: '/api/KS/KSDelete',
            method: 'delete',
            params: { id: id }
        })
            .then((res) => {
                console.log(res);
                if (res.data > 0) {
                    alert("删除成功");
                    getlist();
                    return;
                }
                else {
                    alert("删除失败");
                    return;
                }
            })
            .catch((err) => {
                console.log(err);

            })
    }

}
//==================================修改
const xg = (id: any) => {
    router.push({
        path: '/ksxg',
        query: { id: id }
    })
}
</script>

<style scoped></style>